/*
 * @lc app=leetcode.cn id=238 lang=typescript
 *
 * [238] 除自身以外数组的乘积
 */

// @lc code=start
function productExceptSelf(nums: number[]): number[] {
    const size = nums.length;
    const res = new Array(size);
    const left = new Array(size);
    const right = new Array(size);
    left[0] = 1;

    for (let i = 1; i < size; i++) {
        left[i] = left[i - 1] * nums[i - 1];
    }

    right[size - 1] = 1;
    for (let i = size - 2; i >= 0; i--) {
        right[i] = nums[i + 1] * right[i + 1]
    }
    for (let i = 0; i < size; i++) {
        res[i] = left[i] * right[i]
    }
    return res;
};


// @lc code=end

